home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / RCS / tcpInt.h,v < prev    next >
Encoding:
Text File  |  1989-08-16  |  12.4 KB  |  454 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     89.08.15.19.55.49;  author rab;  state Exp;
  11. branches ;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     89.05.19.14.41.17;  author douglis;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     88.08.16.11.22.14;  author mendel;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.04.27.09.16.00;  author brent;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.04.27.09.02.03;  author brent;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @TCP internal defs
  37. @
  38.  
  39.  
  40. 1.5
  41. log
  42. @Commented #endif labels.
  43. @
  44. text
  45. @/*
  46.  * tcpInt.h --
  47.  *
  48.  *    Internal declarations of data structures for handling the TCP protocol.
  49.  *    The data structures in this file are based on the functional
  50.  *    specification of the Transmission Control Protocol in RFC 793
  51.  *    (Sept. 1981).
  52.  *
  53.  *    Based on the following 4.3BSD files:
  54.  *      "@@(#)tcp_fsm.h   7.2 (Berkeley) 12/7/87"
  55.  *      "@@(#)tcp_seq.h   7.2 (Berkeley) 12/7/87"
  56.  *      "@@(#)tcp_var.h   7.7 (Berkeley) 2/27/88"
  57.  *      "@@(#)tcp_debug.h 7.2 (Berkeley) 12/7/87"
  58.  *
  59.  * Copyright 1987 Regents of the University of California
  60.  * All rights reserved.
  61.  * Permission to use, copy, modify, and distribute this
  62.  * software and its documentation for any purpose and without
  63.  * fee is hereby granted, provided that the above copyright
  64.  * notice appear in all copies.  The University of California
  65.  * makes no representations about the suitability of this
  66.  * software for any purpose.  It is provided "as is" without
  67.  * express or implied warranty.
  68.  *
  69.  *
  70.  * $Header: /sprite/src/daemons/ipServer/RCS/tcpInt.h,v 1.4 89/05/19 14:41:17 douglis Exp Locker: rab $ SPRITE (Berkeley)
  71.  */
  72.  
  73. #ifndef _IPS_TCPINT
  74. #define _IPS_TCPINT
  75.  
  76. #include "sprite.h"
  77. #include "tcpTimer.h"
  78. #include "socket.h"
  79. #include "list.h"
  80. #include "netInet.h"
  81.  
  82.  
  83. /*
  84.  * Define the default maximum segment size to be the size of a default
  85.  * IP segment, minus the header.  On the local net we can make it bigger.
  86.  */
  87. #define TCP_MAX_SEG_SIZE    (NET_IP_MAX_SEG_SIZE - sizeof(Net_TCPHeader))
  88.  
  89. extern int        tcpISS;        /* Initial Send sequence #. */
  90. extern int        tcpKeepLen;    /* Size of data for keep-alive
  91.                      * packets. */
  92.  
  93. /* data structures */
  94.  
  95. /*
  96.  * The various states of the TCP finite state machine.
  97.  * The names are taken from RFC 793, p. 21-2.
  98.  */
  99. typedef enum {
  100.     /* These states are used before a conection is established. */
  101.     CLOSED,        /* Not connected. */
  102.     LISTEN,        /* Waiting for a connection from a remote TCP. */
  103.     SYN_SENT,    /* Have sent a SYN, waiting for reply.  */
  104.     SYN_RECEIVED,    /* Waiting for ACK of our connect request,
  105.              * have ACK'ed the remote's request. */
  106.  
  107.     ESTABLISHED,    /* An open connection -- data can be sent
  108.              * and received. */
  109.  
  110.     /* The remote TCP has closed the connection. */
  111.     CLOSE_WAIT,    /* Got a close request from the remote TCP.
  112.              * Now waiting for the User to close the connection. */
  113.     LAST_ACK,    /* Waiting for the remote TCP to ACK our FIN. */
  114.  
  115.     /* The user has closed the connection. */
  116.     FIN_WAIT_1,    /* User has closed the connection. Have sent a FIN
  117.              * to the remote TCP, waiting for the ACK. */
  118.     FIN_WAIT_2,    /* Got the ACK of our FIN, waiting for the remote
  119.              * TCP's FIN. */
  120.     CLOSING,    /* Got a FIN from the remote TCP, but still waiting
  121.              * for ACK of our FIN. */
  122.  
  123.     TIME_WAIT    /* Waiting for enough time to pass to be sure that
  124.              * the remote TCP received our ACK of its FIN. */
  125. } TCPState;
  126.  
  127. #define TCP_HAVE_RECVD_SYN(state) ((int)state >= (int)SYN_RECEIVED)
  128. #define TCP_UNSYNCHRONIZED(state) ((int)state < (int)ESTABLISHED)
  129. #define TCP_HAVE_RECVD_FIN(state) (state == TIME_WAIT)
  130. #define TCP_HAVE_SENT_FIN(state) ((int)state > (int)CLOSE_WAIT)
  131.  
  132.  
  133. /*
  134.  * From RFC 793, p. 24:
  135.  * "[...] every byte of data sent over a TCP connection has a sequence number."
  136.  * "The sequence number space ranges from 0 to 2**32 -1. Since
  137.  * this space if finite, all arithmetic dealing with sequence numbers
  138.  * must be performed modulo 2**32 [... to preserve] the relationship of
  139.  * sequence numbers as they cycle from 2**32-1 to 0 again."
  140.  */
  141.  
  142. typedef unsigned int TCPSeqNum;
  143.  
  144. #define TCP_SEQ_LT(a, b)    ((int) ((a) - (b)) < 0)
  145. #define TCP_SEQ_LE(a, b)    ((int) ((a) - (b)) <= 0)
  146. #define TCP_SEQ_GT(a, b)    ((int) ((a) - (b)) > 0)
  147. #define TCP_SEQ_GE(a, b)    ((int) ((a) - (b)) >= 0)
  148.  
  149. /*
  150.  * Macros to initialize TCP sequence numbers for send and receive from
  151.  * initial send and receive sequence numbers.
  152.  *
  153.  * TCP_INIT_SEND_SEQ_INCR is the increment added to the initial send
  154.  * sequence number every second.
  155.  */
  156.  
  157. #define TCP_RECV_SEQ_INIT(tcpPtr) \
  158.     (tcpPtr)->recv.advtWindow = (tcpPtr)->recv.next = (tcpPtr)->recv.initial+1
  159.  
  160. #define TCP_SEND_SEQ_INIT(tcpPtr) \
  161.     (tcpPtr)->send.unAck = (tcpPtr)->send.next = (tcpPtr)->send.maxSent = \
  162.     (tcpPtr)->send.urgentPtr = (tcpPtr)->send.initial
  163.  
  164. #define TCP_INIT_SEND_SEQ_INCR    (125 * 1024)
  165.  
  166.  
  167. /*
  168.  * Information about TCP connection attempts from remote hosts. This info
  169.  * is used accept or reject such connections. The queue length is increased
  170.  * by 1 because circular queues waste 1 slot in order to tell if the
  171.  * queue is full or not.
  172.  */
  173.  
  174. #define TCP_MAX_NUM_CONNECTS    5
  175. typedef struct {
  176.     int        maxQueueSize;
  177.     int        head;
  178.     int        tail;
  179.     Sock_InfoPtr    queue[1 + TCP_MAX_NUM_CONNECTS];
  180. } TCPConnectInfo;
  181.  
  182.  
  183. /*
  184.  * Information used to manage TCP data flow to and from remote hosts.
  185.  */
  186.  
  187. typedef struct {
  188.     List_Links    reassList;        /* Segment reassembly list. */
  189.     Net_TCPHeader *templatePtr;        /* Output header template. */
  190.     Net_IPHeader *IPTemplatePtr;    /* IP output header template. */
  191.     TCPConnectInfo *connectPtr;        /* Waiting connection attempts. */
  192.     TCPState    state;            /* State of this connection. */
  193.     int        flags;            /* Defined below. */
  194.     int        timer[TCP_NUM_TIMERS];
  195.     int        rxtshift;        /* Log(2) of retransmit exp. backoff. */
  196.     int        rxtcur;            /* Current retransmit value. */
  197.     int        dupAcks;        /* Consecutive dupl. acks received. */
  198.     int        maxSegSize;        /* Max. segment size. */
  199.  
  200.     /* Transmit timing: */
  201.     int        idle;            /* Inactivity timer. */
  202.     int        rtt;            /* Round-trip time. */
  203.     int        srtt;            /* Smoothed round-trip time. It is
  204.                      * fixed-point with the low-order 3 bits
  205.                      * containing the fraction. */
  206.     int        rttvar;            /* Round-trip time "variance" (actually
  207.                      * a smoothed difference). It is
  208.                      * fixed-point w/ low-order 2 bits
  209.                      * containing the fraction. */
  210.     TCPSeqNum    rtseq;            /* Seq. # used to measure RTT */
  211.  
  212.     char    urgentData;        /* The urgent data octest */
  213.     int        urgentBufPos;        /* Logical location of urgent data in
  214.                      * the receive buffer. */
  215.     Boolean    force;            /* TRUE if forcing out a byte. */
  216.  
  217.     struct {            /* send sequence variables. */
  218.     TCPSeqNum    unAck;        /* oldest acknowledged seq # (snd_una)*/
  219.     TCPSeqNum    next;        /* next seq. # to be sent. (snd_nxt) */
  220.     TCPSeqNum    window;        /* send window size. (snd_wnd) */
  221.     TCPSeqNum    urgentPtr;    /* urgent data offset. (snd_up) */
  222.     TCPSeqNum    updateSeqNum;    /* seq. # use for last window update.
  223.                      * (snd_wl1) */
  224.     TCPSeqNum    updateAckNum;    /* ack # used for last window update.
  225.                      * (snd_wl2) */
  226.     TCPSeqNum    initial;    /* initial seq # sent on SYN packets.
  227.                      * (iss) */
  228.     TCPSeqNum    maxSent;    /* highest seq. # sent, used to
  229.                      * recognize retransmits. (snd_max) */
  230.     unsigned int    congWindow;    /* congestion-controlled window.
  231.                      * (snd_cwnd) */
  232.     unsigned int    cwSizeThresh;    /* congWindow size threshold for
  233.                      * slow start exponential to linear
  234.                      * switch. (snd_ssthresh) */
  235.     int        maxWindow;    /* largest window size the peer
  236.                      * has offered. (max_sndwnd) */
  237.     } send;
  238.  
  239.     struct {            /* receive sequence variables. */
  240.     TCPSeqNum    next;        /* next seq. # expected on incoming
  241.                      * packets. (rcv_nxt) */
  242.     TCPSeqNum    window;        /* recv. window size. (rcv_wnd) */
  243.     TCPSeqNum    urgentPtr;    /* urgent data offset. (rcv_up) */
  244.     TCPSeqNum    initial;    /* initial seq # from peer's SYN
  245.                      * packet. (irs) */
  246.     TCPSeqNum    advtWindow;    /* advertised window size. (rcv_adv) */
  247.     int        maxWindow;    /* largest amount the peer has sent
  248.                      *  into a window. (max_rcvd) */
  249.     } recv;
  250. } TCPControlBlock;
  251.  
  252. /*
  253.  * Definitions of "flags" in the TCP_ControlInfo struct.
  254.  *
  255.  *    TCP_ACK_NOW        - ACK the peer immediately.
  256.  *    TCP_DELAY_ACK        - do an ACK, but try to delay it.
  257.  *    TCP_NO_DELAY        - don't delay packets in order to coalesce.
  258.  *    TCP_IGNORE_OPTS        - don't use the options.
  259.  *    TCP_SENT_FIN        - a FIN has been sent.
  260.  *    TCP_HAVE_URGENT_DATA    - urgent data is ready to be read.
  261.  *    TCP_HAD_URGENT_DATA    - urgent data has been read.
  262.  */
  263.  
  264. #define TCP_ACK_NOW        0x01
  265. #define TCP_DELAY_ACK        0x02
  266. #define TCP_NO_DELAY        0x04
  267. #define TCP_IGNORE_OPTS        0x08
  268. #define TCP_SENT_FIN        0x10
  269. #define TCP_HAVE_URGENT_DATA    0x20
  270. #define TCP_HAD_URGENT_DATA    0x40
  271.  
  272.  
  273. /*
  274.  * Commands for TCPTrace().
  275.  */
  276.  
  277. typedef enum {
  278.     TCP_TRACE_INPUT,
  279.     TCP_TRACE_OUTPUT,
  280.     TCP_TRACE_RESPOND,
  281.     TCP_TRACE_DROP,
  282. } TCPTraceCmd;
  283.  
  284.  
  285. /* procedures */
  286.  
  287. extern void        TCPTrace();
  288. extern void        TCPCloseConnection();
  289. extern void        TCPDropConnection();
  290. extern void        TCPCancelTimers();
  291. extern void        TCPRespond();
  292. extern void        TCPMakeTemplateHdr();
  293. extern ReturnStatus    TCPOutput();
  294. extern TCPControlBlock    *TCPSocketToTCB();
  295. extern TCPControlBlock    *TCPReassemble();
  296. extern Sock_InfoPtr    TCPCloneConnection();
  297. extern TCPControlBlock    *TCPSockToTCB();
  298. extern int        TCPCalcMaxSegSize();
  299. extern void        TCPCleanReassList();
  300. extern void        TCPPrintHdrFlags();
  301. extern void        TCPTimerInit();
  302. extern void        TCPSetPersist();
  303.  
  304. #endif /* _IPS_TCPINT */
  305. @
  306.  
  307.  
  308. 1.4
  309. log
  310. @make TCP_MAX_SEG_SIZE depend on IP max seg size.
  311. @
  312. text
  313. @d5 2
  314. a6 2
  315.  *    The data structures in this file are based on the functional 
  316.  *    specification of the Transmission Control Protocol in RFC 793 
  317. d26 1
  318. a26 1
  319.  * $Header: /sprite/src/daemons/ipServer/RCS/tcpInt.h,v 1.3 88/08/16 11:22:14 mendel Exp Locker: douglis $ SPRITE (Berkeley)
  320. d40 1
  321. a40 1
  322.  * Define the default maximum segment size to be the size of a default 
  323. d46 1
  324. a46 1
  325. extern int        tcpKeepLen;    /* Size of data for keep-alive 
  326. d60 1
  327. a60 1
  328.     SYN_RECEIVED,    /* Waiting for ACK of our connect request, 
  329. d63 1
  330. a63 1
  331.     ESTABLISHED,    /* An open connection -- data can be sent 
  332. d74 1
  333. a74 1
  334.     FIN_WAIT_2,    /* Got the ACK of our FIN, waiting for the remote 
  335. d124 1
  336. a124 1
  337.  * Information about TCP connection attempts from remote hosts. This info 
  338. d164 1
  339. a164 1
  340.                      * fixed-point w/ low-order 2 bits 
  341. d178 1
  342. a178 1
  343.     TCPSeqNum    updateSeqNum;    /* seq. # use for last window update. 
  344. d180 1
  345. a180 1
  346.     TCPSeqNum    updateAckNum;    /* ack # used for last window update. 
  347. d182 1
  348. a182 1
  349.     TCPSeqNum    initial;    /* initial seq # sent on SYN packets. 
  350. d186 1
  351. a186 1
  352.     unsigned int    congWindow;    /* congestion-controlled window. 
  353. d191 1
  354. a191 1
  355.     int        maxWindow;    /* largest window size the peer 
  356. d196 1
  357. a196 1
  358.     TCPSeqNum    next;        /* next seq. # expected on incoming 
  359. d200 1
  360. a200 1
  361.     TCPSeqNum    initial;    /* initial seq # from peer's SYN 
  362. d203 1
  363. a203 1
  364.     int        maxWindow;    /* largest amount the peer has sent 
  365. d214 1
  366. a214 1
  367.  *    TCP_IGNORE_OPTS        - don't use the options. 
  368. d234 1
  369. a234 1
  370.     TCP_TRACE_INPUT, 
  371. d260 1
  372. a260 1
  373. #endif _IPS_TCPINT
  374. @
  375.  
  376.  
  377. 1.3
  378. log
  379. @Converted to new lib.a.
  380. @
  381. text
  382. @d26 1
  383. a26 1
  384.  * $Header: tcpInt.h,v 1.2 88/04/27 09:16:00 brent Exp $ SPRITE (Berkeley)
  385. d39 5
  386. a43 1
  387. #define TCP_MAX_SEG_SIZE    1024
  388. @
  389.  
  390.  
  391. 1.2
  392. log
  393. @New version with Jacobson enhancements
  394. @
  395. text
  396. @d26 1
  397. a26 1
  398.  * $Header: tcpInt.h,v 6.1 88/04/24 23:15:09 andrew Exp $ SPRITE (Berkeley)
  399. @
  400.  
  401.  
  402. 1.1
  403. log
  404. @Initial revision
  405. @
  406. text
  407. @d10 4
  408. a13 4
  409.  *      "@@(#)tcp_fsm.h   7.1 (Berkeley) 6/5/86"
  410.  *      "@@(#)tcp_seq.h   7.1 (Berkeley) 6/5/86"
  411.  *      "@@(#)tcp_var.h   7.2 (Berkeley) 2/19/87"
  412.  *      "@@(#)tcp_debug.h 7.1 (Berkeley) 6/5/86"
  413. d26 1
  414. a26 1
  415.  * $Header: tcpInt.h,v 6.0 87/09/08 15:58:11 andrew Stable $ SPRITE (Berkeley)
  416. d147 3
  417. a149 1
  418.     int        retransShift;        /* log(2) of retransmit exp. backoff. */
  419. d152 11
  420. a162 4
  421.     int        idle;            /* amount of idle time. */
  422.     int        roundTripTime;        /* Round-trip time. */
  423.     float    smoothRTT;        /* smoothed round-trip time. */
  424.     int        rttSeqNum;        /* seq. # used to measure RTT. */
  425. d170 10
  426. a179 7
  427.     TCPSeqNum    unAck;        /* oldest acknowledged seq. #. */
  428.     TCPSeqNum    next;        /* next seq. # to be sent. */
  429.     TCPSeqNum    window;        /* send window size. */
  430.     TCPSeqNum    urgentPtr;    /* urgent data offset. */
  431.     TCPSeqNum    updateSeqNum;    /* seq. # use for last window update. */
  432.     TCPSeqNum    updateAckNum;    /* ack # used for last window update. */
  433.     TCPSeqNum    initial;    /* initial seq # sent on SYN packets. */
  434. d181 6
  435. a186 2
  436.                      * recognize retransmits. */
  437.     unsigned int    congWindow;    /* congestion-controlled window. */
  438. d188 1
  439. a188 1
  440.                      * has offered. */
  441. d193 3
  442. a195 3
  443.                      * packets. */
  444.     TCPSeqNum    window;        /* recv. window size. */
  445.     TCPSeqNum    urgentPtr;    /* urgent data offset.*/
  446. d197 2
  447. a198 2
  448.                      * packet. */
  449.     TCPSeqNum    advtWindow;    /* advertised window size. */
  450. d200 1
  451. a200 1
  452.                      *  into a window. */
  453. @
  454.